﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Kaidou.Persister;
using Kaidou.Model;
using System.Collections.Generic;
using Kaidou.Util;
using Kaidou.Bll;

public partial class master_master_trader : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        LoginModel loginModel = (LoginModel)Session["loginModel"];

        if (loginModel == null)
        {
            Response.Redirect("../login.aspx");
        }
        else if (!loginModel.isOperator())
        {
            Response.Redirect("../menu.aspx");
        }

        string area = Resources.Resource.area;
        string[] areaArray = area.Split(',');
        for (int i = 0; i < areaArray.Length; i++)
        {
            ListItem item = new ListItem();
            item.Value = (i + 1) + "";
            item.Text = areaArray[i];
            trader_pref_code.Items.Insert(i + 1, item);
        }
    }

    protected void login_confirm(object sender, EventArgs e)
    {
        MstTrader model = new MstTrader();
        model.UnionCode = union_code.Text;
        if (!ParameterCheckUtility.isNumber(branch_code.Text.Trim()))
        {
            model.BranchCode = -1;
        }
        else
        {
            model.BranchCode = branch_code.Text.Trim().Length == 0 ? (short)(-1) : short.Parse(branch_code.Text);
        }
        model.TraderRegNo = trader_reg_no1.Text + trader_reg_no2.Text;
        model.TraderRegNo1 = trader_reg_no1.Text;
        model.TraderRegNo2 = trader_reg_no2.Text;
        model.TraderName = trader_name.Text;
        model.TraderKana = trader_kana.Text;
        model.TraderZipNo = trader_zip_no1.Text + trader_zip_no2.Text;
        model.TraderZipNo1 = trader_zip_no1.Text;
        model.TraderZipNo2 = trader_zip_no2.Text;
        model.TraderPrefCode = short.Parse(trader_pref_code.Text);
        model.TraderCity = trader_city.Text;
        model.TraderAddress = trader_address.Text;
        model.TraderTel = trader_tel.Text;
        model.DaihyoName = daihyo_name.Text;
        model.DaihyoKana = daihyo_kana.Text;
        model.RegDate = System.DateTime.Now;
        model.UpdDate = System.DateTime.Now;
        model.UpdUnionCode = (string)Session["Login_Union_code"];
        model.UpdBranchCode = (short)Session["Login_Branch_code"];


        model.TraderSts = MstTrader.STATUS_NORMAL;
        model.UpdFuncId = "insertTrader()";

        //検証
        MST_TraderManager validation = new MST_TraderManager();
        List<string> errorCodeList = validation.checkInsertOrUpdateTrader(model, Resources.Resource.ResourceManager, true);
        msg.Text = ErrorCodeUtil.errorCodeListToHtml(errorCodeList);

        if (errorCodeList.Count == 0)
        {
            Session["mtrader"] = model;
            Response.Redirect("master_trader_conf.aspx");
        }


    }
}
